<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
	<head>
		<title>main</title>

		<link rel="stylesheet" type="text/css"
			href="ext-2.2/resources/css/ext-all.css" />
		<link rel="stylesheet" type="text/css"
			href="ext-2.2/ext-2.2/style.css" />
		<link rel="stylesheet" type="text/css"
			href="ext-2.2/ext-2.2/desktop.css" />
		<link rel="stylesheet" type="text/css"
			href="ext-2.2/ext-2.2/ext-patch.css" />

		<script type="text/javascript" src="ext-2.2/adapter/ext/ext-base.js"></script>
		<script type="text/javascript" src="ext-2.2/ext-all.js"></script>
		<!--  	<script type="text/javascript" src="ext-2.2/source/locale/ext-lang-zh_CN.js"></script>   -->
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	</head>
	
	<script type="text/javascript">
	
		
	</script>

	<script type="text/javascript">

	Ext.BLANK_IMAGE_URL = 'ext-2.2/resources/images/default/s.gif';

	/* 主窗口 */
	Ext.onReady(function() {
				/* 设置提示消息的显示方式 */
				Ext.QuickTips.init();
				Ext.form.Field.prototype.msgTarget = 'side';
				// Ext.Tree.init();
				/* 设置窗口 layout */
				var north, south, west, center;

				/* ================== 菜单 区 ================== */

				// ================== 关闭按钮
				// var fdesc=document.getElementById('fdesc_hid').value;
				// var fuser=document.getElementById('fuser_hid').value;
				var comb1 = '';// '单位：'+fdesc;
				var comb2 = '';// '机构ID：'+fuser;

				function showResult(btn) {
					if (btn == 'yes') {
						window.location.href = 'login.jsp';
						
					}
				};

				var actBtnClose = new Ext.Action({
					text : '注销&nbsp;&nbsp;&nbsp;&nbsp;',
					handler : function() {
						Ext.MessageBox.confirm('提示',
								'<span vlign="middle">确定登出本系统平台 ？</span>',
								showResult);
					},
					iconCls : 'bmenu-close'
				});

				
				/* ================== Top 区 ================== */
				header = new Ext.BoxComponent({ // raw
					region : 'north',
					el : 'north-north-div',
					// tbar: tb,
					border : true,
					height : 90
				// autoHeight:true
				// margins:'3 0 -12 5'
				// autoLoad: {url: 'login2.jsp', scripts: true, scope: this}
				});
				north = new Ext.BoxComponent({ // raw
					region : 'north',
					el : 'toolbar-div',
					// tbar : tb,
					border : false,
					// 在ie下无此项会报错(firefox无事……),默认分别为此布局左、上、右、下的边距,以此防止越界造成的崩溃。
					// 也可写作 'Object:数值'的形式，如 margins：{top: 0, left: 0, right:0,
					// bottom: 0}
					margins : '90 0 2 0'
				// autoLoad: {url: 'login2.jsp', scripts: true, scope: this},
				});

				/* ================== 状态区 ================== */
				south = new Ext.Panel({ // raw
					region : 'south',
					contentEl : 'south-div',// The id of an existing HTML node to
											// use as the panel's body content填充
					titlebar : true,
					split : true,
					height : 80,
					minSize : 80,
					maxSize : 200,
					collapsible : true,
					title : '信息提示',
					margins : '0 0 0 0'
				});

				

				
				center = new Ext.TabPanel({
					region : 'center',
					resizeTabs : true,
					id : 'center-panel',
					cls : 'empty',
					contentEl : 'center-div',
					activeTab : 0,
					activeItem : 0,
					// bodyStyle : 'background:#FFFFFF',
					defaults : {
						autoScroll : true
					},
					// plugins: new Ext.ux.TabCloseMenu(),
					autoScroll : true
				// html:'<br/><br/>&lt;empty center panel&gt;'
				});
				center.add(new Ext.Panel(
								{
									title : '首页',
									iconCls : 'tabs',
									/*
									 * autoLoad : { //url : 'welcome.jsp', url :
									 * 'welcome.action', nocache : true, scripts :
									 * true, scope: this },
									 */
									html : '<html><head></head><body><iframe name="ifr" id="ifr" scrolling="auto" frameborder="0" width="100%" height="100%" '
											+ 'src="welcome.jsp"></iframe></body></html>',
									closable : true
								}));
				center.show();
				/*
				 * center.onResize = function(){ // alert(center.items); //
				 * if(center.items!=null){ // var
				 * grid=center.getComponent('center'); // } center.doLayout();
				 * //alert(grid.width); //center.load(); };
				 */
                
				var root = new Ext.tree.AsyncTreeNode({
					id : "root",
					text : "系统管理",
					children : [ {
						text : "运单管理",
						expanded : true,
						children : [ 
						{
							id : "enterWaybillNum",
							text : "到库货件(0)",
							leaf : true,
							hrefs : 'waybill!queryAdressListAndEenterWaybillList.do'
						}, {
							text : "收获地址管理",
							leaf : true,
							hrefs : 'list_shdz.jsp'
						}, {
							text : "提交新运单",
							leaf : true,
							hrefs : 'waybill!queryAdressListAndEenterWaybillList.do'
						}, {
							text : "当前运单",
							leaf : true,
							hrefs : 'waybill!queryCurrentWaybillByUid.do'
						}, {
							text : "历史运单",
							leaf : true,
							hrefs : 'waybill!queryHistoryWaybillByUid.do'
						} ]
					}, {
					text : "账号信息",
					expanded : true,
					children : [{
							text : "个人资料",
							leaf : true,
							hrefs : 'personalProfile.jsp'
						},{
							text : "修改密码",
							leaf : true,
							hrefs : 'changePassword.jsp'
						},{
							text : "转运地址",
							leaf : true,
							hrefs : 'user!queryUname.do'
						}]						
					}, {
					text : "运单管理",
					expanded : true,
					children : [{
							text : "录入信息",
							leaf : true,
							hrefs : 'enterWaybill.jsp'
						},{
							text : "运单审批(未处理)",
							leaf : true,
							hrefs : "waybill!showAllwbByStatus.do?status=unhandleStatus"
						},{
							text : "运单审批(待付款)",
							leaf : true,
							hrefs :  "waybill!showAllwbByStatus.do?status=unPayforStatus"
						},{
							text : "运单审批(待发货)",
							leaf : true,
							hrefs : "waybill!showAllwbByStatus.do?status=payforUnSendStatus"
						}
						]						
					}, {
						text : "退出系统",
						id : 'logout',
						leaf : true
					} ]
				});
				var tree = new Ext.tree.TreePanel({
					root : root,// 设置为根节点
					region : 'west',
					id : 'west-panel',
					el : 'west-div',
					//titlebar : true,
					title : '　功能导航',
					rootVisible:false,
					autoScroll : true,
					split : true,
					width : 190,
					// minSize : 175,
					// maxSize : 400,
					collapsible : true,
					margins : '0 0 0 5',
					layout : 'accordion',
					layoutConfig : {
						animate : false
					}
				// loader: new Ext.tree.TreeLoader({url:"js/lib/treedata.js"})
				});

				tree.on('expandnode', function(n) {//任何节点张开是执行
					fnode(n);
				});

				/* ================== 内容组合 ================== */
				// var viewport = new Ext.mhis.Viewport({
				var viewport = new Ext.Viewport({
					layout : 'border',
					// items : [header, north, west, center]
					items : [ { // raw
		                region:'north',
		                id:'north-panel',
		                border : false,
		                frame : false,
		                autoLoad: {url: 'top.jsp', scripts: true, scope: this},
		                height:60
		            },tree, center ]
				});
				/*
				 * viewport.addEvents('contextmenu');
				 * viewport.addListener('contextmenu',function(e){ //禁用浏览器自带右键事件
				 * e.preventDefault(); },viewport);
				 * viewport.fireEvent('contextmenu');
				 */

				viewport.addEvents('sysCall');// 添加系统调用事件
				viewport.addListener('sysCall', function() {
					var map = new Ext.KeyMap(Ext.getDoc(), {
						key : Ext.EventObject.Q,
						ctrl : true,
						fn : function(e) {// e 是按键对应的ack码
							Ext.Msg.prompt('SYS150 GORUN', '', function(btn, text) {
								if (btn == 'ok') {
									var bopen = getjsp(new Ext.tree.TreeNode({
										id : text.trim().toLowerCase(),
										leaf : true
									}));
									if (!bopen)
										Ext.Msg.alert('错误', '该应用不存在');
								}
							});
						}
					});
				}, viewport);
				viewport.fireEvent('sysCall');

				// //=================================

				function add() {
					var node1 = Ext.getCmp('treeMenu').getNodeById('root');
					fnode(node1);
				}

				function fnode(node) {
					if (node.isLeaf()) {
					
						// node.un('click',nodeclick);
						node.on('click', nodeclick);
					} else {
					//	alert('目录'+node.text+":"+node.hasChildNodes() + " length:"+node.item.length );
						node.eachChild(function(child) {
							fnode(child);
						});
					}
				}

				function nodeclick(node, event) {
					var hf = node.attributes.hrefs;
					event.stopEvent();
					
					var n = center.getComponent(node.id);
					
					filteropen(node, event, n, hf);
					// 重新加载窗口
					// center.show();windw用
				}
				
				// 注销用户
				function logout(btn) {
					if (btn == 'yes') {
						//window.location.href = 'index.jsp';
						window.location.href = '/logistic/user!logout.do';
					}
				}
				
				/* 暂时不用
				function exportList() {
					Ext.Ajax.request({
						url : "stream/notinput.action",
						params : {},
						success : function(re) {
						},
						failure : function(re, o) {
						}
					});
				}
				*/
				function filteropen(node, event, n, href) {
					
					// 如果点击登出按钮
					if (node.id == 'logout') {
						Ext.MessageBox.confirm('提示',
								'<span vlign="middle">确定退出本系统？</span>', logout);
				//	} else if (node.id == '601') {  暂时没用
				//		exportList();
					} else {
						// 防止重复打开选项卡
						if (!n) {// 如果没有打开选项卡，打开
							load(node, href);
						} else {// 否则显示该选项卡
						//mainpanle.layout.setActiveItem(1);   
						
							n.show();
						}
					}
				}

				function load(node, url) {
					/*
					 * center.load({ url : url.replace('\/*', ''), discardUrl :
					 * false, nocache : true, text : "Loading...", bodyStyle :
					 * 'background:#f1f1f1', timeout : 30, scripts : true });
					 */
					 
					center.add(
									new Ext.Panel(
											{
												id : node.id,// 设置id
												title : node.text,
												iconCls : 'tabs',
												/*
												 * autoLoad : { url :
												 * url.replace('\/*', ''), nocache :
												 * true, scripts : true, scope: this },
												 */
												/*
												 * 使用iframe会出现很多问题，比如弹出详细信息的窗口只能在center区域等
												 */
												// IE6是无法解析 创建iframe前 指定的src属性 的
												html : '<html><head></head><body><iframe name="ifr" id="ifr" scrolling="auto" frameborder="0" width="100%" height="100%" '
														+ 'src="'
														+ url.replace('\/*', '')
														+ '"></iframe></body></html>',
												closable : true
											})).show();
					// 必须要show()完之后，而且不可以用Ext.get("ifr").src = url;
					 ifr.location.href=url.replace('\/*', '');
				}
				function   resetWaybillNum() 
				{
					Ext.Ajax.request({ 
	                      //请求地址 
	                      url: 'waybill!resetWaybillNum.do', 
	                      //成功时回调 
	                      success: function(response, options) { 
	                         //获取响应的json字符串 
	                        var responseArray = Ext.util.JSON.decode(response.responseText);                                               
	                             if(responseArray.success==true){ 
	                            	tree.getNodeById("enterWaybillNum").setText("到库货件("+responseArray.num+")");
	                             } 
	                   	  } 
	             	}); 
			
					setTimeout(resetWaybillNum,5000);//5秒更新一次 
				} 
				resetWaybillNum(); 
				
				
			})

	</script>
	<div id="west-div"></div>
	<div id="center-div"></div>
	
</html>
